< previous page page_30 next page >

Page 30
Finally, ArrangeControls sets the scroll bar's LargeChange property to the amount of visible space. When the user clicks between a scroll bar thumb and a scroll bar arrow, this is the amount by which the value is changed. Setting LargeChange to the amount of visible space makes the control move the image by the amount visible.
Scrolled Window Controls
The method described in the previous section is effective, but it is hardly convenient. You need to write quite a bit of code to make it work. If you wanted to put two scrolled windows on the same form, you would need to repeat all of the code for a new set of picture boxes and scroll bars.
In Visual Basic 5 and later versions, you can create an ActiveX control that implements the scrolled window functionality. The control contains the picture boxes, scroll bars, and the code that manages them. You simply place the scrolled window control on a form and put controls inside it. The control does the rest.
Example program TestSwin, shown in Figure 1.15, demonstrates this approach. The program's form contains four scrolled window controls, each containing a picture. The controls manage each picture separately.
Building ActiveX controls is outside the scope of this book. For detailed information, see the book Custom Controls Library by Rod Stephens, 1998, John Wiley & Sons.
When to Draw
If you place drawing commands in a form's Load event procedure, you may be surprised to find that the form is blank when it appears. The reason is the program draws to the form before the form actually exists on the screen. When the form is finally ready to appear, Visual Basic creates the form blank. Because your drawing commands have already been executed, they do not draw anything on the screen.
There are two general strategies for making graphics appear in a form or picture box: setting AutoRedraw and using the Paint event.
0030-01.jpg
Figure 1.15
Example program TestSwin demonstrates
the ScrolledWindow ActiveX control.

 
< previous page page_30 next page >